from selenium import webdriver
from selenium.webdriver.common.by import By

import time

from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()

driver.get("https://so.gushiwen.cn/user/login.aspx")

# 根据ID 去获取 用户名 密码 登录按钮等 标签
driver.find_element_by_id("email").send_keys("15011073831")

driver.find_element_by_id("pwd").send_keys("chuyi12333")

time.sleep(8)

driver.find_element_by_id("denglu").click()

# 访问搜索元素
search_ele = driver.find_element_by_id("txtKey")
search_ele.send_keys("江雪")

time.sleep(2)
# 输入一个回车键
search_ele.send_keys(Keys.ENTER)

# 收藏
driver.find_element(By.XPATH, "//div[@class='shoucang']/img").click()

time.sleep(2)
# 点击我的 跳转到 我的页面
driver.find_element(By.XPATH, "//div[@class='son1']/a[6]").click()


# 等待2s
time.sleep(2)
# 找到 我们所有的收藏，然后点击第一个
driver.find_element(By.XPATH, "//div[@class='sons']/div[1]/a").click()

# 执行拍照
# driver.get_screenshot_as_file("test.png")
# x = 0
# for i in range(1, 4):
#     driver.get_screenshot_as_file("img/test{}.png". format(i))
#     print("拍照结束")
#     driver.execute_script("window.scrollTo(0, {})".format(i * 200))
